<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="航标名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入航标名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="告警类型" prop="warningType">
        <el-select v-model="queryParams.warningType" placeholder="告警类型" clearable>
          <el-option v-for="dict in dict.type.warn_types" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="告警等级" prop="warningLevel">
        <el-select v-model="queryParams.warningLevel" placeholder="告警等级" clearable>
          <el-option v-for="dict in dict.type.warn_level" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="告警状态" prop="warningStatus">
        <el-select v-model="queryParams.warningStatus" placeholder="告警状态" clearable>
          <el-option v-for="dict in dict.type.warn_status" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:info:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="航标名称" align="center" prop="name" />
      <el-table-column label="mac地址" align="center" prop="mac" />
      <el-table-column label="告警类型" align="center" prop="warningType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.warn_types" :value="scope.row.warningType" />
        </template>
      </el-table-column>
      <el-table-column label="告警等级" align="center" prop="warningLevel">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.warn_level" :value="scope.row.warningLevel" />
        </template>
      </el-table-column>
      <el-table-column label="告警状态" align="center" prop="warningStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.warn_status" :value="scope.row.warningStatus" />
        </template>
      </el-table-column>
      <el-table-column label="告警时间" align="center" prop="warningStartTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.warningStartTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="解除时间" align="center" prop="warningEndTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.warningEndTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button  v-if="scope.row.fbzt == '0'" size="mini" type="text" icon="el-icon-delete" @click="getCk('pf', scope.row)"
            v-hasPermi="['system:info:remove']">工单派发</el-button>
          <el-button  v-if="scope.row.fbzt == '0'" size="mini" type="text" icon="el-icon-delete" @click="getCk('bh', scope.row)"
            v-hasPermi="['system:info:remove']">误报</el-button>
          <el-button v-if="scope.row.fbzt != '0'" size="mini" type="text" icon="el-icon-delete" @click="getCk('ck', scope.row)"
            v-hasPermi="['system:info:remove']">查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改告警数据对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="mac地址" prop="mac">
          <el-input v-model="form.mac" placeholder="请输入mac地址" />
        </el-form-item>
        <el-form-item label="告警等级" prop="warningLevel">
          <el-input v-model="form.warningLevel" placeholder="请输入告警等级" />
        </el-form-item>
        <el-form-item label="开始时间" prop="warningStartTime">
          <el-date-picker clearable v-model="form.warningStartTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间" prop="warningEndTime">
          <el-date-picker clearable v-model="form.warningEndTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="删除标志" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <DetailsM ref="details" :treeForm="treeForm"></DetailsM>
    <gdckLogM ref="gdckLogM"></gdckLogM>
    <gdWbLogM ref="gdWbLogM"></gdWbLogM>
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo } from "@/api/system/gj/gj"
import DetailsM from "@/components/gdLog/detailsM.vue";
import gdckLogM from "@/components/gdLog/gdckLogM.vue";
import gdWbLogM from "@/components/gdLog/gdWbLogM.vue";
export default {
  components: { DetailsM, gdckLogM,gdWbLogM},
  name: "Info",
  dicts: ['warn_level', 'warn_types', 'warn_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      treeForm: { isConserve: "0" },
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 告警数据表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        mac: null,
        deviceType: null,
        warningType: null,
        warningLevel: null,
        warningStartTime: null,
        warningEndTime: null,
        warningStatus: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询告警数据列表 */
    getList() {
      this.loading = true
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        mac: null,
        deviceType: null,
        warningType: null,
        warningLevel: null,
        warningStartTime: null,
        warningEndTime: null,
        warningStatus: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加告警数据"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getInfo(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改告警数据"
      })
    },
    async getCk(type, item) {
      this.pfNum = type;
      if (type == "pf") {
        // this.form.yjid = item.id;
        // this.GdpfDialog = true;
        item.yjid = item.id;
        this.$refs.details.getInit(JSON.parse(JSON.stringify(item)));
        this.$refs.details.open = true;
      } else if (type == "ck") {
        console.log(item, "item");
          this.$refs.gdckLogM.getCk(item.id);
        // this.CkDialog = true;
      } else if (type == "bh") {
        // let obj = { id: item.id };
        // obj.fbzt = 2;
        // obj.clzt = 2;
        // this.wbObj = obj;
        // this.WbDialog = true;
        this.$refs.gdWbLogM.getCk(item);
      }
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除告警数据编号为"' + ids + '"的数据项？').then(function () {
        return delInfo(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => { })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/warning/export', {
        ...this.queryParams
      }, `warn_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
